package com.jpemartin.jgt;

import java.awt.Rectangle;

/**
 * The object will follow ("tail") another object with a given time delay.
 * 
 * @author jpmartin
 */
public class MoveTail implements MoveControl {

  protected Rectangle[] past;
  protected Rectangle _trailed;
  protected int time=0;
  
  public MoveTail(Rectangle trailed, int delay) {
    past = new Rectangle[delay];
    _trailed = trailed;
  }
  
  public void move(Rectangle moved) {
    past[time%past.length]=new Rectangle(_trailed);
    time++;
    if (time<=past.length) {
      moved.x=_trailed.x;
      moved.y=_trailed.y;
      return;
    }
    moved.x = past[time%past.length].x;
    moved.y = past[time%past.length].y;
  }
}
